package io.geekidea.boot.jab.controller;

import io.geekidea.boot.auth.annotation.IgnoreLogin;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.jab.dto.PushMessageDto;
import io.geekidea.boot.jab.dto.QueryParkChannelDto;
import io.geekidea.boot.jab.service.JieAnBoApiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.geekidea.boot.webStock.handler.WebSocketHandler;

@Slf4j
@RestController
@Tag(name = "捷安波智慧停车api")
@RequestMapping("/h5/message")
public class MessageController {

    @Autowired
    private JieAnBoApiService jieAnBoApiService;

    @Autowired
    private  WebSocketHandler webSocketHandler;


    @IgnoreLogin
    @PostMapping("/pushMessage")
    @Operation(summary = "推送接收消息接口")
    @Log(value = "推送接收消息接口", type = SysLogType.ADD)
    public void pushMessage(@RequestBody PushMessageDto dto) {


        // 检查访客是否在线
        if (!webSocketHandler.isVisitorOnline(dto.getVisitorId())) {
            log.warn("Visitor {} is not online", dto.getVisitorId());
            System.out.println("用户不在线"+ dto.getVisitorId());
        }

        // 发送消息
        webSocketHandler.sendMessageToVisitor(dto.getVisitorId(), dto);
    }
}
